package com.example.demo.test2;

public class FruitStore {
  
    // 定义水果类  
    static class Fruit {  
        String name;  
        double pricePerJin;  
  
        Fruit(String name, double pricePerJin) {  
            this.name = name;  
            this.pricePerJin = pricePerJin;  
        }  
  
        double getTotalPrice(int jins) {  
            return jins * pricePerJin;  
        }  
    }  
  
    // 初始化水果  
    static Fruit apple = new Fruit("苹果", 8.0);  
    static Fruit strawberry = new Fruit("草莓", 13.0);  
    static Fruit mango = new Fruit("芒果", 20.0);  
  
    // 计算总价（无促销）  
    public static double calculateTotalPrice(int appleJins, int strawberryJins, int mangoJins) {
        return apple.getTotalPrice(appleJins) + strawberry.getTotalPrice(strawberryJins) + mango.getTotalPrice(mangoJins);  
    }  
  
    // 计算总价（草莓8折）  
    public static double calculateTotalPriceWithDiscount(int appleJins, int strawberryJins, int mangoJins) {  
        double total = calculateTotalPrice(appleJins, strawberryJins, mangoJins);  
        // 草莓8折  
        total -= strawberry.getTotalPrice(strawberryJins) * (1 - 0.8);  
        return total;  
    }  
  
    // 计算总价（草莓8折，满100减10）  
    public static double calculateTotalPriceWithPromotion(int appleJins, int strawberryJins, int mangoJins) {  
        double total = calculateTotalPriceWithDiscount(appleJins, strawberryJins, mangoJins);
        // 购物满100减10  
        if (total >= 100) {  
            total -= 10;  
        }  
        return total;  
    }  
  
    // 主函数，用于测试  
    public static void main(String[] args) {  
        // 顾客A  
        int appleJinsA = 5;  
        int strawberryJinsA = 3;  
        double totalPriceA = calculateTotalPrice(appleJinsA, strawberryJinsA, 0);  
        System.out.println("顾客A购买的总价为：" + totalPriceA + "元");
        System.out.println("------------------");
        // 顾客B  
        int mangoJinsB = 2;  
        double totalPriceB = calculateTotalPrice(appleJinsA, strawberryJinsA, mangoJinsB);  
        System.out.println("顾客B购买的总价为：" + totalPriceB + "元");  
  
        // 顾客C  
        double totalPriceC = calculateTotalPriceWithDiscount(appleJinsA, strawberryJinsA, mangoJinsB);  
        System.out.println("顾客C购买的总价为（草莓8折）：" + totalPriceC + "元");  
  
        // 顾客D  
        double totalPriceD = calculateTotalPriceWithPromotion(appleJinsA * 2, strawberryJinsA * 2, mangoJinsB * 2);  
        System.out.println("顾客D购买的总价为（草莓8折，满100减10）：" + totalPriceD + "元");  
    }  
}